<template>
  <div>
    <el-form :model="detailData.formData" label-position="right" label-width="180px" >
      <el-form-item label="任务说明"  prop="taskDescription">
        <el-input v-model="detailData.formData.taskDescription" type="textarea" mini="middle" placeholder="请输入任务说明" 
          v-if="detailData.isEveryDayTask<2"></el-input>
        <quill-editor class="task" v-model="detailData.formData.taskDescription" v-else></quill-editor>
      </el-form-item>
      <el-form-item label="实时时间" v-if="detailData.isEveryDayTask<2">
        <el-switch class="width220"  v-model="detailData.formData.isNowTime" active-value='1' inactive-value="0" @change="changeNowTime" :disabled="detailData.type==='update'"></el-switch>
      </el-form-item>
      <el-form-item label="开始时间" prop="startDate" v-if="detailData.isEveryDayTask<2">
          <el-date-picker v-model="detailData.formData.startDate" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss"
            type="datetime" placeholder="选择日期时间" class="width220" :disabled="detailData.formData.isNowTime==='1'" ></el-date-picker>
          <el-button type="text" @click="getNowDate('startDate')" v-if="detailData.formData.isNowTime!=='1'">获取当前时间</el-button>
      </el-form-item>
      <el-form-item label="结束时间" prop="endDate" v-if="detailData.isEveryDayTask<2&&(detailData.type==='update'||detailData.formData.isNowTime==='0')">
        <el-date-picker ref="jieshushijian" v-model="detailData.formData.endDate" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" type="datetime" placeholder="选择日期时间" class="width220"></el-date-picker>
        <el-button type="text" @click="getNowDate('endDate')">获取当前时间</el-button>
      </el-form-item>
      <el-form-item label="创建时间"  >
        <el-input v-model="detailData.formData.creatTime" disabled class="width220"></el-input>
      </el-form-item>
        <h3 class="dialog-plate-title"><span>主管评审</span></h3>
        <el-form-item label="主管意见" >
          <el-input v-model="detailData.formData.managerAdvice" :disabled="detailData.type==='insert'" type="textarea" mini="middle" class="width520"></el-input>
        </el-form-item>
        <el-form-item label="主管" >
          <el-input v-model="detailData.formData.managerName"  disabled class="width220"></el-input>
        </el-form-item>
        <el-form-item label="创建时间" >
          <el-input v-model="detailData.formData.adviceCreattime" disabled class="width220"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button  @click="submitProcessState()" type="primary">确 定</el-button>
        </el-form-item>
    </el-form>
  </div>
</template>
<script>
import creatingValueApi from 'plugins/axios/creatingValueApi.js'
import 'quill/dist/quill.core.css';
import 'quill/dist/quill.snow.css';
import 'quill/dist/quill.bubble.css';
import {quillEditor} from 'vue-quill-editor';
export default {
  components:{
    quillEditor
  },
  props:{
    detailData:{
      type:Object,
      required:true
    }
  },
  data(){
    return {}
  },
  methods:{
    /***获取当前时间 */
    getNowDate(type){
      let self = this;
      switch(type){
        case 'startDate':
          self.detailData.formData.startDate = self.timestampToTime(new Date());
          break;
        case 'endDate':
           self.detailData.formData.endDate= self.timestampToTime(new Date())
          break;
      }
    },
    changeNowTime(value){/**实时更改 */
      let self=this;
      self.detailData.formData.isNowTime=value;
      self.detailData.formData.startDate= value=='1'?self.timestampToTime(new Date()):'';
    },
    submitProcessState(){
      let self = this;
      let postData = JSON.parse(JSON.stringify(self.detailData.formData));
      postData.startDate =  postData.startDate ? postData.startDate : null;
      postData.endDate = postData.endDate?postData.endDate:null;
      if( postData.endDate){
          let start = postData.startDate.substr(0, 10);
          let end = postData.endDate.substr(0, 10);
          let date1 = new Date(postData.startDate).getTime();
          let date2 = new Date(postData.endDate).getTime();
          if(start !== end){
            self.$message.error('开始时间和结束时间需要同一天!');
            return false
          }
          if(date1 > date2){
            self.$message.error('开始时间必须早于结束时间!');
            return false;
          }
      }
      creatingValueApi.insertUpdateProcessDetail(self.detailData.type,postData).then(res=>{
        self.$message.success(`${self.detailData.title}成功！`);
        self.$emit('successSubmit')
      })
    }
  }
}
</script>
<style scoped>

</style>